package cn.yangliu.webflux.comm.config;

import cn.yangliu.webflux.comm.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 杨柳
 * @date 2019-12-08
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public JsonResult<?> handler(Exception e) {
        log.error(e.getMessage(), e);
        return JsonResult.getInstance(400, e.getMessage());
    }
}
